package com.fjnldx.mes.mapper.alarm;

import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.fjnldx.mes.domain.domainRes.alarm.AlarmPageRes;
import com.fjnldx.mes.domain.pojo.alarm.AlarmConfig;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Select;
import org.springframework.stereotype.Component;

import java.util.List;

/**
 * 告警配置映射器
 */
@Mapper
@Component
public interface AlarmConfigMapper extends BaseMapper<AlarmConfig> {


    @Select("<script>" +
            "SELECT id,\n" +
            "       name,\n" +
            "       code,\n" +
            "       (SELECT COUNT(1) FROM alarm_rules WHERE alarmId = alarm_config.id) as ruleNumber,\n" +
            "       isActive,\n" +
            "       createTime\n" +
            "FROM alarm_config \n" +
            "WHERE isDeleted = false \n" +
            "<if test='name!=null and name!=\"\"'> AND name LIKE CONCAT('%',#{name},'%') </if> \n" +
            "ORDER BY createTime DESC \n" +
            "LIMIT ${(pageIndex-1)*pageSize},#{pageSize} \n" +
            "</script>")
    List<AlarmPageRes> GetPage(String name, Integer pageIndex, Integer pageSize);

    @Select("<script>" +
            "SELECT COUNT(1) \n" +
            "FROM alarm_config \n" +
            "WHERE isDeleted = false \n" +
            "<if test='name!=null'> AND name LIKE CONCAT('%',#{name},'%') </if> \n" +
            "ORDER BY createTime DESC \n" +
            "</script>")
    Integer GetTotal(String name);
}
